home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-01-24 | 7.6 KB | 285 lines | [TEXT/KAHL] |
- * ***
- * Methods for a class browser
- *
- * Julian Barkway (c) September 1994 All rights reserved.
- *
- * v3.1.0 Initial release
- * v3.1.1 -
- * v3.1.2 - Changed to allow for different actions for double and single clicks.
- * - Increased use of cascades.
- * - addSubClass:instanceVariableNames: patched to let through embedded
- * digits.
- * v3.1.3 - Dictionary pane no longer gives error if clicked on when empty.
- *
- * ***
- Class BrowserWindow Window browser
- Class DictionaryPane SelectListPane dict
- Class Browser Object theClass method compile classPMenu methodPMenu textAreaPMenu cp mp tp
-
- *
- * addSubClass:... patched so that it doesn't remove numbers embedded in instance
- * variable names. The downside is that it will let through some illegal names, but
- * since the compiler will trap these when they are used it probably isn't too bad a
- * side-effect.
- *
- Methods Class 'creation'
- addSubClass: aSymbol instanceVariableNames: aString | newClass |
- newClass <- Class new; name: aSymbol; superClass: self;
- variables:
- (aString words: [:x | x isAlphaNumeric ]).
- aSymbol assign: newClass.
- classes at: aSymbol put: newClass
- ]
-
- *
- * We sub-class Window to allow the 'close' message to be neatly trapped without
- * needing to make Browser a sub-class of Window (which it clearly isn't)
- *
- Methods BrowserWindow 'all'
- openAt: aPosition withSize: aSize
- (title = '') ifTrue: [ " Only false when restoring a saveImage'd window "
- self title: 'Browser ' , (nextBrowserNum asString).
- nextBrowserNum <- nextBrowserNum + 1
- ].
- super openAt: aPosition withSize: aSize
- |
- close | reply |
- (self wantsSave) ifTrue: [
- reply <- smalltalk inquire: ('Save contents of window ', self title, '?').
- (reply isNil) ifTrue: [ "Note: can return nil for Cancel"
- ^ nil
- ].
- reply ifTrue: [
- ((self mainPane) saveContents: 1) ifFalse: [
- ^ nil "User cancelled save operation"
- ]
- ]
- ].
- super close.
- browser close
- |
- browser: aBrowser
- browser <- aBrowser.
- ]
-
- Methods DictionaryPane 'all'
- dictionary: aDictionary
- dict <- aDictionary.
- |
- dictionary
- ^ dict
- |
- setText | t |
- t <- '------------------' , newLine.
- dict binaryDo: [:a :b |
- t <- t , (a asString) , newLine
- ].
- t <- t , '------------------'.
- self clearAllText.
- self text: t
- |
- getSelectedItem | t | " Changed for v3.1.3 "
- dict isNil ifTrue: [
- ^ nil
- ].
- t <- self selectedText.
- ( (t = '------------------') or:
- [t = ('------------------' , newLine) ]) ifTrue: [
- ^ nil
- ].
- t <- t copyFrom: 1 to: ((t size) - 1).
- dict binaryDo: [:a :b |
- ((t asSymbol) == a) ifTrue: [
- ^ b
- ]
- ]
- ]
-
- Methods Browser 'all'
- new | bwin maxW maxH |
- maxW <- (smalltalk getMaxScreenArea) right.
- maxW <- 450 min: (maxW - 70).
- maxH <- (smalltalk getMaxScreenArea) bottom.
- maxH <- 500 min: (maxH - 70).
- bwin <- BrowserWindow new;
- browser: self;
- openAt: (20@60) withSize: (maxW@maxH).
- self makeClassPopUpMenu.
- self makeMethodPopUpMenu.
- self makeTextAreaPopUpMenu.
- self makePanes: bwin.
- |
- makePanes: bwin | ww wh ph pw |
- ww <- (bwin size) x.
- wh <- (bwin size) y.
- pw <- (ww / 2) truncated.
- ph <- (wh / 5) truncated.
- cp <- DictionaryPane new;
- dictionary: classes;
- boundsFrom: (-1 @ -1) to: (pw @ ph);
- attachTo: bwin withSizing: (0 @ 0).
- mp <- DictionaryPane new;
- boundsFrom: ((pw - 1) @ -1) to: ((ww + 1) @ ph);
- attachTo: bwin withSizing: (1 @ 0).
- tp <- TextPane new;
- boundsFrom: (-1 @ (ph - 1)) to: ((ww + 1) @ (wh + 1));
- attachTo: bwin withSizing: (1 @ 1).
- |
- open
- cp font: 'geneva'; fontSize: 9; typeFace: 2;
- button1Action: [:p |
- mp clearAllText.
- classPMenu enableItem: 1; enableItem: 2; enableItem: 3.
- "classPMenu enableItem: 4." "Class removal disabled for now..."
- methodPMenu disableItem: 1; disableItem: 2.
- self cancel
- ];
- button2Action: [:p | classPMenu popUpAt: p ];
- button1DoubleClick: [:p | self selectClass: (cp getSelectedItem) ].
- mp font: 'geneva'; fontSize: 9; typeFace: 2;
- button1Action: [:p |
- self cancel.
- methodPMenu enableItem: 2
- ];
- button2Action: [:p | methodPMenu popUpAt: p ];
- button1DoubleClick: [:p | self selectMethod: (mp getSelectedItem) ].
- tp font: 'monaco'; fontSize: 9;
- button2Action: [:p | textAreaPMenu popUpAt: p ].
- cp setText
- |
- close
- " close our window and remove the pop-up menus"
- classPMenu dispose.
- methodPMenu dispose.
- textAreaPMenu dispose
- |
- selectClass: c
- (c notNil) ifTrue: [
- theClass <- c.
- self showMethods
- ].
- methodPMenu enableItem: 1; disableItem: 2.
- |
- showMethods
- mp dictionary: (theClass methods).
- mp setText
- |
- selectMethod: m
- (m notNil) ifTrue: [
- method <- m.
- tp print: m text.
- compile <- true
- ].
- textAreaPMenu enableItem: 1; enableItem: 2
- |
- makeClassPopUpMenu
- classPMenu <- PopUpMenu new;
- title: '';
- create.
- classPMenu addItem: 'Browse Class'
- action: [ self browseClass: (cp getSelectedItem) ];
- addItem: 'Inspect Class'
- action: [ (cp getSelectedItem) inspect ];
- addItem: 'Add New Class'
- action: [ self addClass ];
- addItem: 'Remove Class'
- action: [ self removeClass: (cp getSelectedItem) ];
- disableItem: 1; disableItem: 4.
- |
- makeMethodPopUpMenu
- methodPMenu <- PopUpMenu new;
- title: '';
- create.
- methodPMenu addItem: 'Add New Method'
- action: [ self addMethod ];
- addItem: 'Remove Method'
- action: [ self removeMethod: (mp getSelectedItem) ];
- disableItem: 1; disableItem: 2.
- |
- makeTextAreaPopUpMenu
- textAreaPMenu <- PopUpMenu new;
- title: '';
- create.
- textAreaPMenu addItem: 'Accept' action: [ self accept ];
- addItem: 'Cancel' action: [ self cancel ];
- disableItem: 1;
- disableItem: 2.
- compile <- true
- |
- browseClass: c | iv |
- " browse the given class "
- (c notNil) ifTrue: [
- tp clearAllText;
- print: (c superClass) printString , ' addSubClass: #' ,
- c printString, newLine;
- print: ' instanceVariableNames: '''.
- iv <- c variables.
- (iv notNil) ifTrue: [
- iv do: [ :var | tp print: ((var asString) , ' ') ]
- ].
- tp print: ''''.
- theClass <- c.
- compile <- false
- ].
- textAreaPMenu disableItem: 1; enableItem: 2.
- |
- addClass
- " add a new class "
- tp clearAllText;
- print: 'superClass addSubClass: #nameOfClass ', newLine,
- ' instanceVariableNames: ''var1 var2'' '.
- compile <- false.
- textAreaPMenu enableItem: 1; enableItem: 2.
- |
- removeClass: c
- " Will remove class from symbols dictionary
- when we can figure out how... It's not just
- a simple matter of invoking removeKey: "
- ^ nil
- |
- addMethod
- method <- Method new.
- tp clearAllText.
- tp print: ' "A comment stating the method''s function"' , newLine.
- tp print: ' messageSelector: argumentNames " -- argument names optional"', newLine.
- tp print: ' | temporaries | "-- temporaries optional"', newLine.
- tp print: ' body of method', newLine.
- compile <- true.
- textAreaPMenu enableItem: 1.
- textAreaPMenu enableItem: 2.
- |
- removeMethod: m | t |
- " Remove given method from currently selected class "
- (m notNil) ifTrue: [
- t <- (smalltalk inquire: 'Remove method ''', (m name), '''?').
- (t isNil) ifTrue: [
- ^ nil
- ].
- t ifTrue: [
- (mp dictionary) removeKey: (m name).
- mp setText.
- methodPMenu disableItem: 2
- ]
- ]
- |
- accept
- compile ifTrue: [ self compile ]
- ifFalse: [ self doCommand ]
- |
- cancel
- tp clearAllText.
- textAreaPMenu disableItem: 1.
- textAreaPMenu disableItem: 2.
-
- |
- compile
- method text: (tp text).
- (method compileWithClass: theClass)
- ifTrue: [ theClass methods at: method name put: method.
- mp setText ].
- |
- doCommand
- " accept tw command "
- [ tp text execute. cp setText ] fork.
- ]
-